//-----------------------------------------------------------------------
// <copyright file="AddToReport.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <author></author>
// <email></email>
// <date>2004-03-23</date>
// <summary>Add a section to a report</summary>
//-----------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks.Summary
{
    using System;
    using Microsoft.Sdc.Tasks.Configuration.SummaryGeneration;
    using Microsoft.Build.Framework;

    /// <summary>
    /// Add a section to a summary report
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[<Summary.AddToReport SectionGenerator="sectionGenerator" ReportFile="reportFile" SourceFolder="sourceFolder" FileSpec="fileSpec" Name="name" />]]></code>
    /// <para>where:</para>
    /// <para><i>sectionGenerator (Required)</i></para>
    /// <para>Fully qualified type name for the section generator class. Can be any of the following:
    ///
    /// "Microsoft.Sdc.Tasks.Configuration.SummaryGeneration.Generators.CodeCoverageSectionGenerator"
    /// "Microsoft.Sdc.Tasks.Configuration.SummaryGeneration.Generators.NUnitSectionGenerator"
    /// "Microsoft.Sdc.Tasks.Configuration.SummaryGeneration.Generators.SolutionSectionGenerator"
    /// "Microsoft.Sdc.Tasks.Configuration.SummaryGeneration.Generators.StyleCopSectionGenerator"
    /// </para>
    /// <para><i>reportFile (Required)</i></para>
    /// <para>The full path and filename to the file that will contain the summary report.</para>
    /// <para><i>sourceFolder</i></para>
    /// <para>The full path to the folder that contains the specified section's xml files to be summarised.</para>
    /// <para><i>fileSpec</i></para>
    /// <para>The search string specifying the file(s) to be summarised, for example "Report*.dll"</para>
    /// <para><i>name</i></para>
    /// <para>Optional name to identify one section from another</para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///         <Summary.AddToReport 
    ///                 SourceFolder="$(MSBuildProjectDirectory)\Output" 
    ///                 FileSpec="testsummary.xml" 
    ///                 ReportFile="$(MSBuildProjectDirectory)\Output\BuildReport.xml" 
    ///                 SectionGenerator="Microsoft.Sdc.Tasks.Configuration.SummaryGeneration.Generators.NUnitSectionGenerator"
    ///                 Name="Test"
    ///         </Summary.AddToReport>
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>
    public class AddToReport : TaskBase
    {
        private string sourceFolder;
        private string fileSpec;
        private string reportFile;
        private string sectionGenerator;
        private string name;

        /// <summary>
        /// The full path to the folder that contains the specified section's xml files to be summarised.
        /// </summary>
        /// <value>The full path to the folder that contains the specified section's xml files to be summarised.</value>
        public string SourceFolder
        {
            get
            {
                return this.sourceFolder;
            }
            set
            {
                this.sourceFolder = value;
            }
        }

        /// <summary>
        /// The search string specifying the file(s) to be summarised.
        /// </summary>
        /// <value>The search string specifying the file(s) to be summarised, for example "Report*.dll"</value>
        public string FileSpec
        {
            get
            {
                return this.fileSpec;
            }
            set
            {
                this.fileSpec = value;
            }
        }

        /// <summary>
        /// The full path and filename to the file that will contain the summary report.
        /// </summary>
        /// <value>The full path and filename to the file that will contain the summary report.</value>
        [Required]
        public string ReportFile
        {
            get
            {
                return this.reportFile;
            }
            set
            {
                this.reportFile = value;
            }
        }

        /// <summary>
        /// Name of the class that will generate this section
        /// </summary>
        /// <value>TODO</value>
        [Required]
        public string SectionGenerator
        {
            get
            {
                return this.sectionGenerator;
            }
            set
            {
                this.sectionGenerator = value;
            }
        }

        /// <summary>
        /// Optional name to identify one section from another (especially if they
        /// are the same type)
        /// </summary>
        /// <value></value>
        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            Report report = new Report();
            Section section = report.CreateSection(SectionGenerator, SourceFolder, FileSpec, this.Name);
            report.Add(section, ReportFile);
        }

        /// <summary>
        /// Initializes a new instance of the AddToReport class.
        /// </summary>
        public AddToReport()
        {
        }
    }
}